﻿using System;
using System.Collections.Generic;

namespace Util.TitleParser
{
    public sealed class TitleParser
    {
        private TitleParser()
        {
        }

        private static List<ITitleParser> parsers = new List<ITitleParser>();

        static TitleParser()
        {
            parsers.Add(new Parse_SssEee());
            parsers.Add(new Parse_sxee());
            parsers.Add(new Parse_see());
        }

        public static void ParseTitle(string title, out string name, out string details, out long season, out long episode)
        {
            foreach (ITitleParser p in parsers)
            {
                try
                {
                    p.ParseTitle(title, out name, out details, out season, out episode);
                    if (name.Length != 0 && details.Length != 0 && season != 0 && episode != 0)
                    {
                        return;
                    }
                }
                catch (Exception)
                {
                }
            }
            throw new ArgumentException("Couldn't parse Title", "Title");
        }
    }
}
